package com.oocl.aeat.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.oocl.aeat.dto.JsonResult;
import com.oocl.aeat.service.VerifyService;
import com.oocl.aeat.service.factory.VerifyServiceFactory;
import com.oocl.aeat.util.Const;
import com.oocl.aeat.util.JsonUtil;

@WebServlet("/sec/muser/block")
public class BlockServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private Logger logger = Logger.getLogger(BlockServlet.class);
	private VerifyService verifyService;
    public BlockServlet() {
    	verifyService = VerifyServiceFactory.getInstance();
    }
    
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		JsonResult result = null;
		String mid=request.getParameter("mid");
		String block=request.getParameter("block");
		if(mid!=null && block!=null){
			if(verifyService.modifyBlock(mid, Integer.parseInt(block))){
				logger.info("mid="+mid+" block is "+block);
				result = new JsonResult(Const.JSON_SUCCESS, "success", null);
			}else{
				result = new JsonResult(Const.JSON_FAIL, "mid cannot found. M_USER and VERIFY not synchronization.", null);
			}
		}else{
			result = new JsonResult(Const.JSON_FAIL, "mid or block cannot null", null);
		}
		out.write(JsonUtil.getJsonFromObject(result));
		out.flush();
	}

}
